<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <style>
    .box {
      width: 200px;
      height: 300px;
      border: 3px solid red;
      position: absolute;
      top: 200px;
      left: 50%;
      transform: translate(-50%, 0);
      overflow: hidden;
    }
    .contaner {
      height: 100%;
      width: 800px;
      position: absolute;
      left: 0;
      top: 0;
      transition: all 0.3s;
    }
    .img {
      height: 100%;
      width: 200px;
      float: left;
    }
    .img img {
      width: 100%;
      height: 100%;
    }
  </style>
  <body>
    <button>第一张</button>
    <button>第二张</button>
    <button>第三张</button>
    <button>第四张</button>
    <div class="box">
      <div class="contaner">
        <div class="img">
          <img src="./img/1.jpg" alt="" />
        </div>
        <div class="img">
          <img src="./img/2.jpg" alt="" />
        </div>
        <div class="img">
          <img src="./img/3.jpg" alt="" />
        </div>
        <div class="img">
          <img src="./img/5.jpg" alt="" />
        </div>
      </div>
    </div>
  </body>
  <script>
    let btns = document.querySelectorAll("button");
    let contaner = document.querySelector(".contaner");
    for (let i = 0; i < btns.length; i++) {
      btns[i].onclick = function () {
        contaner.style.left = -i * 200 + "px";
      };
    }
  </script>
</html>
